import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_core_widget/utils/toast_util.dart';
import 'package:kq_flutter_widgets/widgets/pullDown/pull_down_menu_simple.dart';
import 'package:kq_flutter_widgets/widgets/pullDown/entity/drop_down_option.dart';
import 'package:kq_flutter_widgets/widgets/titleBar/kq_title_bar.dart';

class KqPullDownMenuSimplePage extends StatefulWidget {
  const KqPullDownMenuSimplePage({super.key});

  @override
  State<KqPullDownMenuSimplePage> createState() =>
      _KqPullDownMenuSimplePageState();
}

class _KqPullDownMenuSimplePageState extends State<KqPullDownMenuSimplePage> {
  List<List<DropDownOption>> list = [];

  Future<List<List<DropDownOption>>> getTestData() {
    return Future.delayed(const Duration(milliseconds: 500), () {
      return [
        [
          DropDownOption("title1", "titleId1"),
          DropDownOption("title1", "titleId2"),
          DropDownOption("title1", "titleId3"),
          DropDownOption("title1", "titleId4"),
          DropDownOption("title1", "titleId5"),
          DropDownOption("title1", "titleId6"),
        ],
        [
          DropDownOption("title2", "titleId1"),
          DropDownOption("title2", "titleId2"),
          DropDownOption("title2", "titleId3"),
          DropDownOption("title2", "titleId4"),
          DropDownOption("title2", "titleId5"),
          DropDownOption("title2", "titleId6"),
          DropDownOption("title2", "titleId7"),
          DropDownOption("title2", "titleId8"),
          DropDownOption("title2", "titleId9"),
          DropDownOption("title2", "titleId10"),
          DropDownOption("title2", "titleId11")
        ],
        [
          DropDownOption("title3", "titleId1"),
          DropDownOption("title3", "titleId2"),
          DropDownOption("title3", "titleId3"),
          DropDownOption("title3", "titleId4"),
          DropDownOption("title3", "titleId5"),
          DropDownOption("title3", "titleId6"),
          DropDownOption("title3", "titleId7"),
          DropDownOption("title3", "titleId8"),
          DropDownOption("title3", "titleId9"),
          DropDownOption("title3", "titleId10"),
          DropDownOption("title3", "titleId11")
        ],
        [
          DropDownOption("title4", "titleId1"),
          DropDownOption("title4", "titleId2"),
          DropDownOption("title4", "titleId3"),
        ]
      ];
    });
  }

  @override
  void initState() {
    super.initState();
    getTestData().then((value) {
      list = value;
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: KqHeadBar(
        headTitle: '下拉菜单演示',
        back: () {
          Get.back();
        },
      ),
      body: PullDownMenuSimple(
        listData: list,
        chosenData: [
          "单选1",
          "多选1",
          DropDownOption("多选2", "null"),
          DropDownOption("单选2", "null")
        ],
        callBack: (data, index) {
          KqToast.showNormal(data.title);
        },
        callBackMulti: (data, index) {
          ///返回一组数据
        },
        isMultiChoose: (index) {
          if (index == 2 || index == 1) {
            return true;
          } else {
            return false;
          }
        },
        saveKey: (index) {
          if (index == 2) {
            return "test1";
          } else if (index == 1) {
            return "test2";
          }
          return null;
        },
      ),
    );
  }
}
